package com.leo.app.view;

import com.leo.app.View;
import com.leo.app.input.Key;
import com.leo.app.input.Mouse;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;

import static com.leo.Framework.*;

/**
 * @ClassName HomeView
 * @Description
 * @Author wangss
 * @date 2020.12.07 21:15
 * @Version 1.0
 */
public class HomeView extends View {

    public Button playButton;

    public Button exitButton;

    @Override
    public void onLaunch() {
        playButton = new Button("play");
        exitButton = new Button("exit");

        VBox vBox = new VBox(10, playButton, exitButton);
        vBox.setAlignment(Pos.CENTER);
        getChildren().add(vBox);

        playButton.setOnAction(event -> {
            UIApp.gotoView(PlayView.class.getName());
        });

        exitButton.setOnAction(event -> {
            UIApp.exit();
        });
    }

    @Override
    public void onFinish() {

    }

    /**
     * 这里说明一下， AnimationTimer 启动以后，会不停的执行 handle ，然后 handle 方法中调用了 onUpdate
     * 也就是说 onUpdate 是不停的刷新执行的，相当于里边的逻辑在不停的执行，才可以判断按键是否被触发
     *
     * @param time
     */
    @Override
    public void onUpdate(double time) {
        System.out.println("homeview = " + time);
        if (keyInput.isPressed(Key.A)) {
            System.out.println("Pressed A");
        }

        if (keyInput.isHold(Key.B)) {
            System.out.println("Hold B");
        }

        if (keyInput.isReleased(Key.B)) {
            System.out.println("Released B");
        }

        if (keyInput.isTyped(Key.C)) {
            System.out.println("Type C " + keyInput.getTypeCount(Key.C));
        }

        if (mouseInput.isPressed(Mouse.LEFT)) {
            System.out.println("Pressed left");
        }

        if (mouseInput.isPressed(Mouse.MIDDLE)) {
            System.out.println("Pressed middle");
        }

        if (mouseInput.isPressed(Mouse.RIGHT)) {
            System.out.println("Pressed right");
        }
    }
}
